package br.uefs.cedoc.controle.serie;


import br.uefs.cedoc.controle.*;
import br.uefs.cedoc.db.exception.DBConnectionException;
import br.uefs.cedoc.db.serie.DBSerie;
import javax.servlet.http.HttpServletRequest;
import br.uefs.cedoc.entidades.*;
import java.sql.SQLException;


public class AddSerieCommand implements Command {
    
    private String next;
    private boolean debug=false;
    
    public AddSerieCommand(String next) {
        this.next = next;
    }
    
    public String execute(HttpServletRequest req)
    throws CommandException {
        try {
            if(debug){
            DBSerie dbserie = new DBSerie();
            SerieBean serie = new SerieBean();            
            serie.setSerie("gregory");
            dbserie.criarSerie(serie);
            }
            if(CommandToken.isValid(req)){
            DBSerie dbserie = new DBSerie();
            SerieBean serie = new SerieBean();            
            //serie.setSerie("gregory");
            serie.setSerie(req.getParameter("serie"));
            dbserie.criarSerie(serie);
            req.setAttribute("status.msg", "Serie adicionada!");
            }
            else{
                req.setAttribute("status.msg", "Nao foi possivel adicionar!");
            }
            
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (DBConnectionException ex) {
                ex.printStackTrace();
            }
        return next;

    }
}
